package com.ryan.security.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;

/**
 * Created by kaimin on 1/1/2019.
 * time : 13:45
 */
//@Aspect
//@Component //加扫描注解才会起作用
public class TimeAspect {


    //切面方式，切入表达式 切入逻辑
    @Around("execution(* com.ryan.security.controller.UserController.*(..))")
    public Object handControllerMethod(ProceedingJoinPoint pjp){
        System.out.println("time aspect start");
        long start = new Date().getTime();
//        filterChain.doFilter(servletRequest,servletResponse);
        try {
            Object[] args = pjp.getArgs();
            for (Object a:args
                 ) {
                System.out.println("ars is "+a);
            }
            Object proceed = pjp.proceed();

        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("time ="+(new Date().getTime()-start));
        System.out.println("time aspect finish");
        return null;
    }
}
